package logic

import (
	"activity/activityRpc/activityRpc"
	"activity/activityRpc/internal/svc"
	"context"

	"activity/models/mysql"
	"github.com/zeromicro/go-zero/core/logx"
)

type AddActivityLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddActivityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddActivityLogic {
	return &AddActivityLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddActivityLogic) AddActivity(in *activityRpc.AddActivityRequest) (*activityRpc.AddActivityResponse, error) {
	// todo: add your logic here and delete this line

	activity := mysql.Activity{
		Title:         in.Title,
		ActivityImage: in.ActivityImage,
		Info:          in.Info,
		UserId:        int(in.UserId),
	}

	mysql.DB.Create(&activity)

	return &activityRpc.AddActivityResponse{
		Id: int64(activity.ID),
	}, nil
}
